﻿using UnityEngine;
using System.Collections;

public class WalkingSpeed : MonoBehaviour {
	
	float vertical = 0f;
	float speed = 0f;
	private Animator anim;


	// Use this for initialization
	void Awake () {
		anim = this.transform.GetComponent<Animator>();
	
	}
	
	// Update is called once per frame
	void Update () {


		speed = Mathf.Abs(vertical);
		anim.SetFloat("Speed", speed, 0.01f, Time.deltaTime);

//		if(Input.GetKey(KeyCode.Q)){
//			anim.SetFloat("Turn", -1, 0.1f, Time.deltaTime);
//			this.transform.Rotate(Vector3.up * (Time.deltaTime + -2), Space.World);
//		}
//		
//		else if (Input.GetKey(KeyCode.E)){
//			anim.SetFloat("Turn", 1, 0.1f, Time.deltaTime);
//			this.transform.Rotate(Vector3.up * (Time.deltaTime + 2), Space.World);
//		}
//		
//		else { anim.SetFloat("Turn", 0, 0.1f, Time.deltaTime); }

		//SpeedUp
		if (Input.GetKey (KeyCode.UpArrow))
		{
			vertical += 1f;
		}
		//SpeedDown
		else if (Input.GetKey (KeyCode.DownArrow))
		{
			vertical -= 1f;
		}



		if(anim.speed>=1.5f)
		{
			anim.speed = 0.65f*vertical*Time.deltaTime;
		}
		else
		{
			anim.speed = 1.5f;
		}


	}

//	void OnTriggerEnter (Collider   collisionInfo) {
//
//			Debug.Log("Name：" + collisionInfo.gameObject.tag);
//		
//
//		if(collisionInfo.gameObject.tag == "cube"){
//
//
//
//
//			Debug.Log("Name：" + collisionInfo.gameObject.name);
//			Destroy(collisionInfo.gameObject);
//		}
//    }


	void OnCollisionEnter(Collision collision) {

		Debug.Log("Name：" + collision.gameObject.tag);
		
		if(collision.gameObject.tag == "cube"){
			
			Debug.Log("Name：" + collision.gameObject.name);
			Destroy(collision.gameObject);
		}
	}




		
}
